package com.sky.test;

import com.sky.jedis.util.JedisConnectionFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.Map;

public class JedisTest2 {
    private Jedis jedis;
    @BeforeEach
    public void init(){
        //1.建立连接
        //jedis = new Jedis("localhost",6379);
        jedis = JedisConnectionFactory.getJedis();

    }
    @Test
    void testString(){
        //存入数据
        String result = jedis.set("name", "zhangsan");
        System.out.println(result);
        //获取数据
        String name = jedis.get("name");
        System.out.println(name);
    }

    @Test
    void testHash(){
        //插入hash数据
        jedis.hset("user:1","name","zhangsan");
        jedis.hset("user:1","age","18");

        //获取hash数据
        Map<String, String> user1 = jedis.hgetAll("user:1");
        System.out.println(user1);
    }
    @AfterEach
    void teardown(){
        if (jedis != null){
            jedis.close();
        }
    }
}
